﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MayfairFramework
{
    /// <summary>
    /// List の拡張クラスです。
    /// </summary>
    public static class ListExtensions
    {
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list"></param>
        /// <param name="fromIndex"></param>
        /// <param name="toIndex"></param>
        /// <returns></returns>
        public static IList<T> SubList<T>(this IList<T> list, int fromIndex, int toIndex)
        {
            IList<T> ret = new List<T>();
            if (fromIndex == toIndex)
            {
                return ret;
            }
            for (int i = fromIndex; i <= toIndex; i++)
            {
                ret.Add(list[i]);
            }
            return ret;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list"></param>
        /// <param name="items"></param>
        /// <returns></returns>
        public static IList<T> AddAll<T>(this IList<T> list, IList<T> items)
        {
            foreach (T item in items)
            {
                list.Add(item);
            }
            return list;
        }
    }
}
